//index.js
//获取应用实例
const app = getApp()
var util = require('../../utils/util.js')
Page({
  data: {
    time:"",
    temperature: "22",
    humidity: "",
    info: "阴",
    city:"成都",
    wid: "",
    direct: "",
    power: "",
    futureData:""
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onTapDayWeather(){
    wx.navigateTo({
      url: '/pages/future/future?futureData=' + this.data.futureData,
    })
  }
  ,
  onLoad: function () {
  var TIME = util.formatTime(new Date());
  this.setData({
      time: TIME
  })
   wx.request({
     url: 'http://apis.juhe.cn/simpleWeather/query?city=%e6%88%90%e9%83%bd&key=8eeb117ead3c0ed455435f38a550ddeb',
     success:(res)=>{
       console.log(res)
       console.log(res.data.result.future)
       this.setData({
         temperature: res.data.result.realtime.temperature,
         info: res.data.result.realtime.info,
         direct: res.data.result.realtime.direct,
         city: res.data.result.city,
         futureData : JSON.stringify(res.data.result.future),
         time: TIME
       })
       console.log(typeof JSON.stringify(res.data.result.future))
     },
     
   })
    
  },
  getUserInfo: function(e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  onPullDownRefresh: function(){
    wx.request({
      url: 'http://apis.juhe.cn/simpleWeather/query?city=%e6%88%90%e9%83%bd&key=8eeb117ead3c0ed455435f38a550ddeb',
      success: (res) => {
        console.log(res)
        this.setData({
          temperature: res.data.result.realtime.temperature,
          info: res.data.result.realtime.info,
          direct: res.data.result.realtime.direct,
          city: res.data.result.city,
        })
      },
    })
    var jinxReport;
    wx.showToast({
      title: '下拉刷新成功',
      icon:'none'
    })
  } 
})
